//
//  SEMessageInquiryCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/16.
//

import UIKit

class SEMessageInquiryCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = .white
        contentView.backgroundColor = .white
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        contentView.backgroundColor = highlighted ? Asset.textGrayLightest.color.withAlphaComponent(0.3) : .white
    }

    func update(with viewModel: SEInquiryInfoViewModel) {
        avatarImageView.kf.setAvatarImage(urlString: viewModel.info.otherPhoto,
                                          placeholder: viewModel.doctorAvatarPlaceholder)
        nameLabel.text = viewModel.info.receiverName
        messageLabel.text = viewModel.content
        timeLabel.text = viewModel.dateTime
        msgCountLabel.text = viewModel.unReadCount
        msgCountLabel.isHidden = viewModel.unReadHidden
    }
    
    @IBOutlet private weak var avatarImageView: UIImageView!
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var messageLabel: UILabel!
    @IBOutlet private weak var timeLabel: UILabel!
    @IBOutlet private weak var lineView: UIView!
    
    @IBOutlet private weak var msgCountLabel: UILabel! {
        didSet {
            msgCountLabel.layer.cornerRadius = msgCountLabel.height / 2
            msgCountLabel.layer.masksToBounds = true
            msgCountLabel.adjustsFontSizeToFitWidth = true
        }
    }
}
